home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
Future.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
3KB
|
116 lines
" NAME Future
AUTHOR miw@cs.man.ac.uk
FUNCTION An implementation of the "future" control construct
ST-VERSIONS 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY Future
is an implementation of the MultiLisp 'future' control
structure. This is a bare-bones version and is superceded by
Parallelism.st
(2.2). MIW
"!
'From Smalltalk-80, version 2, of April 1, 1983 on 18 February 1987 at 4:46:06 pm'!
Object subclass: #Future
instanceVariableNames: 'result semaphore '
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel-Processes'!
Future comment:
'I represent an execution in progress. Any messages sent to me are delayed until execution has completed.'!
!Future methodsFor: 'synchronising'!
doesNotUnderstand: aMessage
semaphore wait.
semaphore signal. "Wake up anything else that might be waiting"
^result perform: aMessage selector withArguments: aMessage arguments! !
!Future methodsFor: 'evaluating'!
block: aBlock
"Execute aBlock in parallel with whatever called me, but ensure that any messages sent to me before execution of the block has terminated are suspended until it has terminated."
semaphore _ Semaphore new.
[result _ aBlock value. semaphore signal] fork!
block: aBlock value: aValue
semaphore _ Semaphore new.
[result _ aBlock value: aValue. semaphore signal] fork!
block: aBlock value: value1 value: value2
semaphore _ Semaphore new.
[result _ aBlock value: value1 value: value2.
semaphore signal] fork!
block: aBlock value: value1 value: value2 value: value3
semaphore _ Semaphore new.
[result _ aBlock value: value1 value: value2 value: value3.
semaphore signal] fork!
block: aBlock valueWithArguments: anArray
semaphore _ Semaphore new.
[result _ aBlock valueWithArguments: anArray.
semaphore signal] fork! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Future class
instanceVariableNames: ''!
!Future class methodsFor: 'examples'!
example
| fac |
fac _ [100 factorial] futureValue.
Transcript show: 'evaluating factorial...'.
Transcript show: fac printString
"Future example"! !
!Future class methodsFor: 'class initialization'!
initialize
superclass _ nil "must avoid the checks"
"Future initialize"! !
Future initialize!
!BlockContext methodsFor: 'parallel evaluation'!
futureValue
"Fork a synchronised evaluation of myself"
^Future new block: self!
futureValue: aValue
"Fork a synchronised evaluation of myself"
^Future new block: self value: aValue!
futureValue: value1 value: value2
"Fork a synchronised evaluation of myself"
^Future new block: self value: value1 value: value2!
futureValue: value1 value: value2 value: value3
"Fork a synchronised evaluation of myself"
^Future new block: self value: value1 value: value2 value: value3!
futureValueWithArguments: anArray
"Fork a synchronised evaluation of myself"
^Future new block: self valueWithArguments: anArray! !